import {Service} from "@/core/service";
import {store} from "@/main";

function registerRedux(target: any, propertyKey: any, properties: TypedPropertyDescriptor<any>) {
    let oldValue = target[propertyKey];

    target.muations = target.muations || {};
    target.muations[propertyKey] = oldValue;

    properties.value = function(...args:any[]) {
        store.dispatch(oldValue.apply(target, args));
    };

    return properties
}

export function actions() {
    return function (target:Object,propertyKey:any, properties:TypedPropertyDescriptor<any>) {
        return registerRedux(target, propertyKey, properties)
    }
}


export abstract class ReduxService extends Service{
      get store (){
        return store.getState()[this.serviceName]
      }
}
